<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../../inc/conn.asp"-->
<!--#include file="../common/u.asp"-->
<%links="package"

Set rsPackage=conn.execute("select count(id) from Package where uid='"&uid&"'") 
PackageNull=rsPackage(0)
if PackageNull<>"0" then
  set rss=conn.execute("select * from Package where uid='"&uid&"'")
  if not rss.eof then
	InterTransCostx=rss("InterTransType")
	PackageCostx=rss("PackageType")
	addressID=rss("Aid")
	weight=rss("weight")
	content=rss("content")
  set rss=nothing
  end if


  '计算运费
	  set rsne=server.CreateObject("adodb.recordset")
	  sql="select price from InterTransCost where fid="&InterTransCostx&" and Startweight<'"&weight&"' and Endweight>='"&weight&"'"
	  rsne.open sql,conn,1,3
	  if not rsne.eof then
		InterTransprice=rsne("price")
	  rsne.close
	  set rsne=nothing
	  end if



  '计算运费
	  set rsne=server.CreateObject("adodb.recordset")
	  sql="select price from PackageCost where fid="&PackageCostx&" and Startweight<'"&weight&"' and Endweight>='"&weight&"'"
	  rsne.open sql,conn,1,3
	  if not rsne.eof then
		Packageprice=rsne("price")
	  rsne.close
	  set rsne=nothing
	  end if

  
  
  '送货信息
  set rss=conn.execute("select * from address where uid='"&uid&"' and id="&addressID&"")
  if not rss.eof then
	codezip=rss("codezip")
	Location=rss("Location")
	name=rss("name")
	mobile=rss("mobile")
	strtel=rss("tel")
  set rss=nothing
  end if
  



end if





%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>包裹管理</title>
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
</head>
<body>

<!--#include file="../../common/top.asp"-->






<div class="fullwidth">
	<div class="place ">
		<a href="/">首页</a> &gt; <a href="/user">会员中心</a> &gt; 包裹管理
	</div>
</div>
<!--main-->
<div class="fullwidth bg1">
	<div class="main">
		
		<!--#include file="../common/left.asp"-->
		
		<div class="right_show f_r">
			<div class="title_4">
				<h2>付款</h2><div></div>
			</div>
			
			<p class="tip">
				本次的付款您将获得<font class="red">10点</font>积分
			</p>
			<div class="clear20"></div>
			
			<div class="sure_pay">
				<form action="" method="">
					<table class="stable stable_1">
						<tr>
							<td class="select_td_1">总费用</td>
							<td><font class="red"><%=(cdbl(InterTransprice)+cdbl(Packageprice))*CDBL(web_rate)%> RMB</font></td>
						</tr>
						<tr>
							<td class="select_td_1">账户余额</td>
							<td><font class="red"><%=formatNumber(money,2,-1)%> RMB</font><a href="" class="recharge">立即去充值</a></td>
						</tr>
					</table>
			    <div class="clear20"></div>
					<div class="sure_btn sure_btn_1">
						<a href="?pay=yes" class="success_btn">确认付款</a>
					</div>
				</form>
			</div>
		</div>
		
		
	</div>
</div>

<div class="clear"></div>



<!--#include file="../../common/footer.asp"-->


<%
if request.QueryString("pay")="yes" then

      '判断余额是否满足
	  if (cdbl(money)-cdbl((cdbl(InterTransprice)+cdbl(Packageprice))*CDBL(web_rate)))<0 then
	  response.Write "<div class=""pop_content"">余额不足，<a href=""javascript:adClick('/user/money/recharge', '/user/package/payment');"">去充值</a></div><div class=""pop_bg""></div>"
	  response.end 
	  end if
	  
	  
	  
	  '产生订单号（内部和外部）及定单产生日期及其他信息
	  BranchID="0022"
	  CoNo="000040"
	  '交易日期，格式：YYYYMMDD
	  yy=right(year(date),2)
	  mm=right("00"&month(date),2)
	  dd=right("00"&day(date),2)
	  riqi=yy & mm & dd
	  '生成订单号所有所需元素,格式为：小时，分钟，秒
	  xiaoshi=right("00"&hour(time),2)
	  fenzhong=right("00"&minute(time),2)
	  miao=right("00"&second(time),2)
	  '产生外部和内部定单号
	  BillNo=xiaoshi & fenzhong & miao
	  inBillNo=yy & mm & dd & "" & xiaoshi & fenzhong & miao
	  '订单号生成完成
	  '判断订单号是否生成成功
	  if inBillNo="" then
		response.Write "<div class=""pop_content"">系统繁忙，请刷新重试 <a href=""javascript:history.back(-1)"">返回</a></div><div class=""pop_bg""></div>"
		response.end
	  end if
	  
	  
	  
	  '更新订单商品
	  '读取购物车信息
	  set rslistx=server.CreateObject("adodb.recordset")
	  sql="select * from View_Package where isPackage=1 and uid='"&uid&"'"
	  rslistx.open sql,conn,1,3
	  if not rslistx.eof then
	  do while not rslistx.eof 
        
		 if rslistx("typeid")="1" then
		   conn.execute("update AuctionsOrder set Mark=6 where uid='"&uid&"' and id = "&rslistx("id")&"")
		 else
		   conn.execute("update OrderDetail set Mark=7 where uid='"&uid&"' and id = "&rslistx("id")&"")
		 end if
		 
		  '订单产品写入
		  Set rsdetail=server.createobject("adodb.recordset")
		  rsdetail.Open "select * from PackageOrderDetail" ,conn,2,3
		  rsdetail.AddNew 
		  rsdetail("order")=inBillNo  '订单编号
		  rsdetail("oid")=rslistx("id")
		  rsdetail("typeid")=rslistx("typeid")
		  rsdetail.Update
		  rsdetail.close
		  set rsdetail=nothing
		 
 
	  rslistx.movenext
	  loop
	  rslistx.close
	  set rslistx=nothing
	  end if
	  '订单产品信息写入完成
	  
	  
	  
	  '订单列表信息写入
	  Set rsadd=server.createobject("adodb.recordset")
	  rsadd.Open "select * from PackageOrder" ,conn,2,3
	  rsadd.AddNew 
	  rsadd("order")=inBillNo '订单号
	  rsadd("uid")=uid '会员id
	  rsadd("Rate")=web_rate '汇率
	  rsadd("InterTransType")=InterTransCostx '国际运输方式
	  rsadd("InterTransCost")=InterTransprice     '国际运输费用
	  rsadd("PackageType")= PackageCostx      '包装类型ID
	  rsadd("PackageCost")=Packageprice       '包装费用
	  rsadd("IsUsedSafety")=0       '是否加保险
	  rsadd("SafetyCost")=0       '保险费用
	  rsadd("SaveCost")=0       '库房滞留费用
	  rsadd("TransCost")=0       '转运费用
	  rsadd("weight")=weight       '重量
	  rsadd("Location")=Location       '所在地
	  rsadd("CodeZip")=codezip       '邮编
	  rsadd("TEL")=strtel&" "&mobile       '电话
	  rsadd("Name")= name      '姓名
	  rsadd("Flag")=1      '已付款
	  rsadd("content")=content
	  rsadd.Update
	  rsadd.close
	  set rsadd=nothing
	  '订单列表信息写入完成


	  
	  '扣除余额
	  conn.execute("update [user] set money=money-"&cdbl((cdbl(InterTransprice)+cdbl(Packageprice))*CDBL(web_rate))&" where uid='"&uid&"'") 
	  
	  '写入资金明细
	  set rsx=server.createobject("adodb.recordset")
	  sql="select * from funds" 
	  rsx.open sql,conn,1,3
	  rsx.addnew  
	  rsx("Uid")=uid
	  rsx("money")="-"&(cdbl(InterTransprice)+cdbl(Packageprice))*CDBL(web_rate)
	  rsx("Balance")=cdbl(money)-(cdbl(InterTransprice)+cdbl(Packageprice))*CDBL(web_rate)
	  rsx("content")=inBillNo&"付款"
	  rsx("Type")=1
	  rsx("PayType")=2
	  rsx("mark")=1
	  rsx.update
	  rsx.close
	  set rsx=nothing
	  
	  '删除记录
	  conn.execute("delete from Package where uid='"&uid&"'")
	  session("PackageMoney")=(cdbl(InterTransprice)+cdbl(Packageprice))*CDBL(web_rate)
	  
	  response.Redirect "/user/package/paysuccess"
	  

end if
%>



</body>
</html>